package com.fc.hkx.api;

import com.fc.hkx.common.ResponseJson;
import com.fc.hkx.thirdparty.feiyou.FeiyouApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by futurecreative on 2017/9/8.
 */
@RestController
@RequestMapping("/api")
public class FeiyouController {
    @Autowired
    private FeiyouApiService feiyouApiService;

    @RequestMapping("/feiyou/weather")
    public ResponseJson getWeather(@RequestParam("airport") String airport) throws Exception {
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(feiyouApiService.getWeather(airport));
        return responseJson;
    }

    @RequestMapping("/feiyou/preflight")
    public ResponseJson getPreflight(@RequestParam("fnum") String fnum,
                                     @RequestParam("dep") String dep,
                                     @RequestParam("arr") String arr,
                                     @RequestParam("date") String date) throws Exception {
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(feiyouApiService.getPreflight(fnum, dep, arr, date));
        return responseJson;
    }

    @RequestMapping("/feiyou/comfort")
    public ResponseJson getComfort(@RequestParam(value="fnum", required = false) String fnum,
                                     @RequestParam(value="dep", required = false) String dep,
                                     @RequestParam(value="arr", required = false) String arr,
                                     @RequestParam("date") String date) throws Exception {
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(feiyouApiService.getComfort(fnum, dep, arr, date));
        return responseJson;
    }

    @RequestMapping("/feiyou/flight")
    public ResponseJson getFlight(@RequestParam("fnum") String fnum,
                                @RequestParam("date") String date) throws Exception {
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(feiyouApiService.getFlight(fnum, date));
        return responseJson;
    }

    @RequestMapping("/feiyou/path")
    public ResponseJson getPath(@RequestParam("fnum") String fnum,
                                   @RequestParam("dep") String dep,
                                   @RequestParam("arr") String arr,
                                   @RequestParam("date") String date) throws Exception {
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(feiyouApiService.getPath(fnum, dep, arr, date));
        return responseJson;
    }

}
